package com.anycl.design.j2ee.frontcontroller;

import lombok.extern.slf4j.Slf4j;

import java.util.Random;

/**
 * 前端控制器
 */
@Slf4j
public class FrontController {
    private Dispatcher dispatcher;

    public FrontController(Dispatcher dispatcher) {
        this.dispatcher = dispatcher;
    }

    public void dispatchRequest(String request) {
        requestLog(request);
        if (isAuthenticationUser()) {
            dispatcher.dispatch(request);
        } else {
            log.info("权限校验失败");
        }

    }

    private void requestLog(String request) {
        log.info("请求：" + request);
    }

    /**
     * 权限校验（模拟）
     */
    private boolean isAuthenticationUser() {
        return new Random().nextBoolean();
    }
}
